package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.ActivityInfoDto;
import com.crm.jdy.common.dto.ClientChargeInfoDto;
import com.crm.jdy.common.pojo.ActivityInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.ActivityInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
*
* <p>说明： 商务活动API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月25日
*
*/
@Validated
@Api(tags = "activityInfo", description = "商务活动")
@RestController
@RequestMapping("/activityInfo")
public class ActivityInfoController{

    @Reference(version = "${service.version}", check = false)
    ActivityInfoService activityInfoService;

    @RateLimit()
    @ApiOperation("活动信息")
    @PostMapping("/seleteactivityInfo")
    public ResultVo seleteChargeInfo( @RequestBody ActivityInfoDto activityInfo){
        PageInfo<ActivityInfo> list = activityInfoService.seleteActivityInfoPageInfo(activityInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新联系人")
    @PostMapping("/updatactivityInfo")
    public ResultVo updatactivityInfo(@ApiParam(value = "activityInfo", required = true)
                                      @Validated @RequestBody ActivityInfo activityInfo){
        boolean index = activityInfoService.updateActivityInfo(activityInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加联系人")
    @PostMapping("/addActivityInfo")
    public ResultVo addActivityInfo(@ApiParam(name = "activityInfo", required = false)
                                   @Validated @RequestBody ActivityInfo activityInfo){
        boolean list  = activityInfoService.addActivityInfo(activityInfo);
        return  ResultVo.success(list);
    }


    @RateLimit()
    @ApiOperation("删除联系人")
    @DeleteMapping("deleteActivityInfo/{activityId}")
    public ResultVo deleteActivityInfo(@NotNull  @ApiParam(name = "activityId", value = "activityId", required = false)
                                       @PathVariable String activityId){
        boolean b = activityInfoService.removeActivityInfo(activityId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}